<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    const person = {
        name: "jack",
        age: 21,
        language: ['java', 'js', 'css']
    }
    //获取key形成数组
    console.log(Object.keys(person))
    //获取value形成数组
    console.log(Object.values(person))
    //获取key和value形成二维数组 数组
    console.log(Object.entries(person))

    const target = { a: 1 };
    const source1 = { b: 2 };
    const source2 = { c: 3 };
    //{a:1,b:2,c:3}
    Object.assign(target,source1,source2)
    console.log(target)

    // 声明对象简写
    const age = 23
    const name = "张三" 
    const person2 = {age,name}
    console.log(person2) 

    //对象函数简写
    let person3 = {
        name: "jack",
        //以前
        eat:function(food){
            console.log(this.name+" eat:"+food)
        },
        //箭头函数this不能使用，对象.属性
        eat2: food => console.log(person3.name+" eat:"+food),
        eat3(food){
            console.log(this.name+" eat:"+food)
        }
    }
    person3.eat("apple")
    person3.eat2("pear")
    person3.eat3("banana")

    //  拷贝对象（深拷贝）
    let person4 = {...person}
    console.log(person4)

    //  合并对象，如果有重复的，后面对象字段值会覆盖原来对象的字段值
    let age1 = { age: 15 }
    let name1 = { name: "Amy" }
    let person5 = {name:"zhangsan"}
    person5 = {...age1,...name1}
    console.log(person5)
</script>
</html>